package com.tadpole.music.adapter.question;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.tadpole.music.R;
import com.tadpole.music.adapter.base.BaseAdapter;
import com.tadpole.music.bean.question.SimulationBean;
import com.tadpole.music.holder.base.BaseViewHolder;
import com.tadpole.music.holder.question.SimulationViewHolder;

import java.util.List;

/**
 * 模拟套题
 * Created By 孙岩
 * on 2020/9/14
 */
public class SimulationAdapter extends BaseAdapter {
    private OnItemClickListener onItemClickListener;
    private OnChildClickListener onChildClickListener;
    private SimulationViewHolder simulationViewHolder;
    private Activity activity;
    private int flag;//0显示3个，1显示多个
    private List<SimulationBean.DataBeanX.DataBean> list;

    public SimulationAdapter(Activity activity,int flag,List<SimulationBean.DataBeanX.DataBean> list){
        this.activity = activity;
        this.flag = flag;
        this.list = list;
    }



    @Override
    public BaseViewHolder createRelHolder(ViewGroup parent, int viewType) {
        simulationViewHolder = new SimulationViewHolder( LayoutInflater.from(activity).inflate(R.layout.item_simulation, parent, false),onChildClickListener,list);
        return simulationViewHolder;
    }

    @Override
    public int getRelItemCount() {
        if(flag==0){
            return Math.min(list.size(), 3);
        }else {
            return list.size();
        }

    }

    @Override
    public void setOnItemClickListener(OnItemClickListener listener) {

    }

    @Override
    public void setOnChildClickListener(OnChildClickListener listener) {
        this.onChildClickListener = listener;
    }

    @Override
    public void setOnLongClickListener(OnLongClickListener listener) {

    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder holder, int position) {
        holder.init(position - mHeadViews.size());
    }
}
